package main

import (
	"fmt"
)

/*
  建造者模式 例子：造灯
*/

//定义 颜色 品牌 属性
type color string
type brand string

//建造者接口
type Builder interface {
	Color(color) LampBuilder
	Brand(brand) LampBuilder
	Build() Lamp
}
//灯的建造者
type LampBuilder struct {
	Lamp
}
//灯
type Lamp struct {
	color color
	brand brand
}


func (l LampBuilder) Color(c color) LampBuilder {
	l.color = c
	return l
}

func (l LampBuilder) Brand(b brand) LampBuilder  {
	l.brand = b
	return l
}

func (l LampBuilder) Build() Lamp {
	 return  Lamp{color:l.color,brand:l.brand}
}

func NewBuilder() Builder {
	return LampBuilder{}
}


func main()  {
	//创建一个 红色 的 A品牌 的 灯
    builder := NewBuilder()
    lamp := builder.Color("red").Brand("A").Build()
    fmt.Println(lamp)
}


